<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>项目劳务公司关系查看</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">
</head>
<body>
<div style="padding: 10px;">
    <from class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">项目名称</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input type="text" id="projectName" name="projectName" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="width: auto;">施工单位名称</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input type="text" id="builderName" name="builderName" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="width: auto;">劳务公司名称</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input type="text" id="companyName" name="companyName" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layui-btn-normal" data-type="search" id="btnSearch">查询</button>
            </div>
        </div>
    </from>
</div>
<table class="layui-table" lay-filter="tbFliter" id="tbData" style="margin-top: -25px;">
</table>
<script src="../assets/layui/layui.js"></script>
<script>
    layui.config({
        base: '../js/'
    });

    layui.use(['jquery','table','common','laydate'], function () {

        var table = layui.table,
            common=layui.common,
            laydate=layui.laydate,
            $ = layui.jquery,
            active = {
                search: function () {
                    table.reload("tbOptions", {
                        where: {
                            projectName: $("#projectName").val(),
                            builderName: $("#builderName").val(),
                            companyName: $("#companyName").val()
                        },page:{
                            curr: 1
                        }
                    });
                },
                doAdd: function () {
                    common.layer_show("项目新增",'projectAdd.html?type=add&op='+op,'100%','100%');
                },
                doImport:function () {

                },
                doExport:function () {

                }
            };
        var op=common.getUrlParam("op");

        //表格初始化
        table.render({
            elem: '#tbData'
            , skin: 'row'
            , url: '../builder/proBulidComList'
            , page: true
            , cols: [[
                {field: 'id', title: '序号',width: 80}
                ,{field: 'projectName', title: '项目名称'}
                ,{field: 'builderName', title: '施工单位'}
                ,{field: 'builder_user_phone', title: '施工单位账号'}
                ,{field: 'companyName', title: '劳务公司'}
                ,{field: 'company_user_phone', title: '劳务公司账号'}
                ,{field: 'operation', title: '操作',align:'left',
                    templet: function (e) {
                        var html = '';
                        if (e.userType == '2') {
                            html += ' <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="del">删除</a>';
                        }
                        return html;
                    }
                }
            ]]
            , limits: [10, 20, 50]
            , where: {
                projectName: $("#projectName").val(),
                companyName: $("#companyName").val(),
                builderName: $("#builderName").val(),
                op: op
            }
            , id: 'tbOptions'
        });
        
        table.on('tool(tbFliter)', function (obj) {
            var data = obj.data; //获得当前行数据
            var id = data.id;
            var layEvent = obj.event; //获得 lay-event
            if (layEvent === 'del') { //删除
                var str="删除";
                layer.confirm('您确定'+str+'该项目吗', function (index) {
                    $.ajax({
                        type: 'POST',
                        url: '../builder/deleteRes',
                        dataType: 'json',
                        data: {id: id},
                        success: function (rtn) {
                            if (rtn.code == 0) {
                                common.showMsg('操作成功!');
                                table.reload("tbOptions", {
                                    where: {
                                        projectName: $("#projectName").val(),
                                        companyName: $("#companyName").val(),
                                        builderName: $("#builderName").val()
                                    },page:{
                                        curr: 1
                                    }
                                });
                                // obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                            }
                            else {
                                common.showError("操作失败:" + rtn.msg);
                            }
                        },
                        error: function () {
                            common.showError("操作失败");
                        }
                    });
                });

            }
        });
        //按钮事件绑定
        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>